<html>
<head><meta charset="utf-8"><title>tinyvec without default · wg-secure-code · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/index.html">wg-secure-code</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/tinyvec.20without.20default.html">tinyvec without default</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="213587862"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/tinyvec%20without%20default/near/213587862" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eh2406 <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/tinyvec.20without.20default.html#213587862">(Oct 16 2020 at 17:11)</a>:</h4>
<p>So I am working on a library that has a data structure that tends to be 1,2,meny in length. Using <a href="https://docs.rs/smallvec/1.4.2/smallvec/">smallvec</a> gets a 1.5x perf improvement over using std::Vec. I know that <code>smallvec</code> does not have a great reputation. <a href="https://docs.rs/tinyvec/1.0.1/tinyvec/">tinyvec</a> has a default requirement that I don't want to leek to my api. <br>
How bad is smallvec?<br>
Are there more alternatives in this space?</p>



<a name="213588628"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/tinyvec%20without%20default/near/213588628" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/tinyvec.20without.20default.html#213588628">(Oct 16 2020 at 17:17)</a>:</h4>
<p>I don't think there's any reason not to use smallvec, known bugs have all been fixed to my knowledge</p>



<a name="213911405"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/tinyvec%20without%20default/near/213911405" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/tinyvec.20without.20default.html#213911405">(Oct 20 2020 at 12:33)</a>:</h4>
<p><span class="user-mention" data-user-id="120179">@Eh2406</span> If you don't need to dereference to a slice of your elements, you can store some elements on the stack safely by wrapping them in an <code>Option</code> and initializing the backing array to <code>None</code>. This avoids all unsafe code in a similar way to TinyVec. Otherwise you'll need to either require Default or deal with uninitialized memory.<br>
You can verify SmallVec using <a href="https://github.com/jakubadamw/rutenspitz">https://github.com/jakubadamw/rutenspitz</a> - this will tell you how bad it is, and find any glaring bugs for relatively cheap. SmallVec already has a hand-rolled fuzzing harness to that effect, since recent vulns have put it under more scrutiny.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>